package com.example.service.Imp;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.StringUtils;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.example.common.b_pojo.Musicuser;
import com.example.common.dto.Register;
import com.example.common.pojo.musicuser;
import com.example.common.utils.R;
import com.example.dao.MusicUserMapper;
import com.example.dao.mapper.BMusicuserMapper;
import com.example.service.MusicUserservice;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

@Service
@Transactional
public class MusicUserserviceImp extends ServiceImpl<MusicUserMapper, musicuser> implements MusicUserservice {

    @Autowired
    private BMusicuserMapper bmusicUserMapper;

    @Override
    public R<String> registerservice(Register register) {
        musicuser musicuser1 = new musicuser();
        BeanUtils.copyProperties(register,musicuser1,"code");
        if (StringUtils.isBlank(register.getName())
                || StringUtils.isBlank(register.getUserimg())
                || StringUtils.isBlank(register.getPhone())
        ){
            return R.error("传过来的数据存在空值");
        }
        boolean save = this.save(musicuser1);
        if (!save){
            return R.error("注册失败，请联系管理员！");
        }
        return R.success("注册成功！");
    }

    @Override
    public Page<Musicuser> gethasdeletelist(int pageNum, int pageSize) {
        Page<Musicuser> page = new Page<>(pageNum, pageSize);
        LambdaQueryWrapper<Musicuser> wapper = new LambdaQueryWrapper<>();
        Page<Musicuser> musicuserPage = bmusicUserMapper.selectPage(page, wapper);
        return musicuserPage;
    }

    @Override
    public Page<Musicuser> getAlllist(int pageNum, int pageSize) {
        Page<Musicuser> page = new Page<>(pageNum, pageSize);
        LambdaQueryWrapper<Musicuser> wapper = new LambdaQueryWrapper<>();
        Page<Musicuser> musicuserPage=bmusicUserMapper.selectAllList(page, wapper);
        return musicuserPage;
    }

    @Override
    public boolean b_updateById(Musicuser musicuser) {
        int i = bmusicUserMapper.updateById(musicuser);
        if (i>0){
            return true;
        }
        return false;
    }

    @Override
    public Musicuser getuserByName(String username) {
        Musicuser musicuser = bmusicUserMapper.getuserByName(username);
        if (musicuser!=null){
            return musicuser;
        }
        return null;
    }

    @Override
    public Musicuser getuserById(Long id) {
        Musicuser musicuser = bmusicUserMapper.selectById(id);
        if (musicuser!=null){
            return musicuser;
        }
        return null;
    }

    @Override
    public boolean startRoleByRoleId(Long id) {
        int i = bmusicUserMapper.startRoleByRoleId(id);
        if (i>0){
            return true;
        }
        return false;
    }

    @Override
    public boolean deleteUser(Long id) {
        boolean b = bmusicUserMapper.removeUserById(id);
        if (b){
            return true;
        }
        return false;
    }


}
